# Contributor: Alexander Georgievskiy <galeksandrp@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=fdk-aac
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.2
pkgrel=2
pkgdesc="A standalone library of the Fraunhofer FDK AAC code from Android (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
url="https://github.com/mstorsjo/${_realname}"
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/v${pkgver}.tar.gz")
sha256sums=('7812b4f0cf66acda0d0fe4302545339517e702af7674dd04e5fe22a5ade16a90')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  ./autogen.sh
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd ${srcdir}/build-${CARCH}

  make DESTDIR=${pkgdir} install
  
  # Install license
  install -dm 755 "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac
  install -m 644 "${srcdir}"/${_realname}-${pkgver}/NOTICE "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac/
}
